home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / basic / ScrollText.lha / ScrollText / ScrollText.asc next >
Encoding:
Text File  |  2000-08-29  |  6.0 KB  |  234 lines

  1.  
  2.  
  3. ; $VER: ScrollText.bb2 v1.1 (29.08.2000)
  4.  
  5. ; Author: Damir Arh
  6. ; E-mail: damir.arh@telesat.si
  7. ; WWW:    http://damir.gajba.net/
  8.  
  9. ; This source code is completely free. You can redistribute
  10. ; and/or modify it without any restrictions whatsoever.
  11.  
  12. ;-------------------------------------------------------------
  13.  
  14. ; These functions easily enable you to include some
  15. ; scrolling text into your program.
  16.  
  17. ; At the end of this source ('main' label) there's a small
  18. ; demo to show you, how they should be used. You don't need
  19. ; to include this part into your program, but you should
  20. ; include everything else.
  21.  
  22. ; Before compiling you have to convert a picture with font
  23. ; data into the appropriate format with the program ST_Font.
  24. ; You need 'ST_Font.iff' where the characters are sorted from
  25. ; left till the right border and then from up to down like:
  26.  
  27. ;  0  1  2  3  4  5  6
  28. ;  7  8  9 10 11 12 13
  29. ; ...
  30.  
  31. ; The characters are set in following order:
  32. ;  0-25: letters of English alphabet (A-Z)
  33. ; 26-35: numbers (0-9)
  34. ;    36: (.)
  35. ;    37: (!)
  36. ;    38: (?)
  37. ;    39: (,)
  38. ;    40: empty space
  39.  
  40. ; The final executable doesn't need any external files but
  41. ; at compilation time you need 'ST_Font.dat' (made with
  42. ; ST_Font) and ST_Font.col (palette file).
  43.  
  44. ;-------------------------------------------------------------
  45.  
  46.  
  47. ;-------------------------------------------------------------
  48. .ST_Const's:
  49. ;-------------------------------------------------------------
  50.  
  51. ; First group of constants can be changed to suit the routines
  52. ; to personal needs.
  53. ; Don't touch the others, if you don't know, what you're
  54. ; doing!!
  55.  
  56. #ST_Width=320
  57. #ST_OffSet=0       ; first shape to fill with characters
  58. #ST_Y=120          ; y position of the text
  59. #ST_Size=16        ; size of the font (square!)
  60. #ST_Speed=1        ; amount of pixels moved in one step
  61. #ST_TextSize=50    ; maximal length of text
  62.  
  63. #ST_Characters=41  ; number of supported characters
  64. #ST_Fullstop=36    ;\
  65. #ST_Exclamation=37 ; positions
  66. #ST_Question=38    ; of
  67. #ST_Branch=39      ; punctuation
  68. #ST_Space=40       ;/
  69. #ST_Numbers=26     ; starting position of 'number' shapes
  70.  
  71. Dim ST_Shapes.b(#ST_TextSize)     ; make the array
  72.  
  73. Goto ST_Init       ; skip the decoding part
  74.  
  75. ;-------------------------------------------------------------
  76. .ST_Load:
  77. ;-------------------------------------------------------------
  78.  
  79. ; Include and decode the needed data. Must be called before
  80. ; ST_Update. Palette will be put in slot 0, shapes from
  81. ; #ST_OffSet above.
  82.  
  83. DecodePalette 0,?ST_Palette
  84. DecodeShapes #ST_OffSet,?ST_Font
  85.  
  86. Return
  87.  
  88. ST_Font:
  89.   IncBin "ST_Font.dat"
  90.  
  91. ST_Palette:
  92.   IncBin "ST_Font.col"
  93.  
  94.  
  95. ;-------------------------------------------------------------
  96. .ST_Init:
  97. ;-------------------------------------------------------------
  98.  
  99. ; This function makes the necessary initialization.
  100. ; ST_Update won't work without it.
  101.  
  102. ; Parameter:
  103. ; text$ - text to scroll
  104.  
  105. Statement ST_Init {text$}
  106.  
  107.   SHARED ST_Shapes.b(), ST_Length.w, ST_Pos.w
  108.  
  109.   ST_Length=Len(text$)      ; get the length of text
  110.                                      ; properly
  111.   For i=1 To ST_Length
  112.                                      ; convert the text to
  113.     c$=Mid$(text$,i,1)               ; internal format
  114.     a.b=Asc(c$)                      ;
  115.  
  116.     If a>=Asc("A") AND a<=Asc("Z")   ; upper-case letters
  117.       ST_Shapes(i-1)=a-Asc("A")
  118.     EndIf
  119.  
  120.     If a>=Asc("a") AND a<=Asc("z")   ; lower-case letters
  121.       ST_Shapes(i-1)=a-Asc("a")
  122.     EndIf
  123.  
  124.     If a>=Asc("0") AND a<=Asc("9")   ; numbers
  125.       ST_Shapes(i-1)=#ST_Numbers+a-Asc("0")
  126.     EndIf
  127.  
  128.     ; punctuation marks
  129.     If a=Asc(".") Then ST_Shapes(i-1)=#ST_Fullstop
  130.     If a=Asc("!") Then ST_Shapes(i-1)=#ST_Exclamation
  131.     If a=Asc("?") Then ST_Shapes(i-1)=#ST_Question
  132.     If a=Asc(",") Then ST_Shapes(i-1)=#ST_Branch
  133.     If a=Asc(" ") Then ST_Shapes(i-1)=#ST_Space
  134.  
  135.   Next i
  136.  
  137.   ST_Pos=0                         ; initialize the position
  138.  
  139. End Statement
  140.  
  141.  
  142. ;------------------------------------------------------------
  143. .ST_Update:
  144. ;------------------------------------------------------------
  145.  
  146. ; This function draws the next position of the scrolling
  147. ; text to the active bitmap
  148.  
  149. Statement ST_Update{}
  150.  
  151.   SHARED ST_Shapes(), ST_Length, ST_Pos
  152.  
  153.   Boxf 0,#ST_Y,#ST_Width,#ST_Y+#ST_Size,1 ; clear previous step
  154.  
  155.   ; update the position of the text
  156.   ST_Pos=ST_Pos+#ST_Speed
  157.   If ST_Pos>ST_Length*#ST_Size+#ST_Width Then ST_Pos=0
  158.  
  159.   pos=ST_Pos              ; position of the current character
  160.   char=0                  ; current character
  161.  
  162.   While pos>0             ; if the text already appeared
  163.  
  164.     If pos<#ST_Width+#ST_Size         ; if it's on the screen
  165.  
  166.       If char<ST_Length              ; if the text isn't over
  167.  
  168.         If pos<#ST_Size OR pos>#ST_Width
  169.           ClipBlit ST_Shapes(char)+#ST_OffSet,#ST_Width-pos,#ST_Y
  170.         Else
  171.           Blit ST_Shapes(char)+#ST_OffSet,#ST_Width-pos,#ST_Y
  172.         EndIf
  173.  
  174.       EndIf
  175.  
  176.     EndIf
  177.  
  178.     pos=pos-#ST_Size  ; next character
  179.     char=char+1       ;/
  180.  
  181.   Wend
  182.  
  183. End Statement
  184.  
  185.  
  186. ;------------------------------------------------------------
  187. .main:
  188. ;------------------------------------------------------------
  189.  
  190. ; This is just a short program to test the above functions.
  191.  
  192. ; It shows, how to use the functions correctly and shouldn't
  193. ; be directly copied into your program.
  194.  
  195. #_Width=$80000023                   ;\
  196. #_Height=$80000024                  ; some tags
  197. #_Depth=$80000025                   ; to open
  198. #_BitMap=$8000002E                  ; the screen
  199. #_Exclusive=$8000003F               ;/
  200.  
  201. text$="A small routine for scrolling text..." ; test text
  202.  
  203. ; Decode the data and initialize the text.
  204. ; Call these two before ST_Update.
  205.  
  206. WBStartup
  207.  
  208. Gosub ST_Load
  209. ST_Init{text$}
  210.  
  211. BitMap 0,320,256,5                  ; open screen
  212. Cls 0
  213. BitMap 1,320,256,5                  ; and bitmaps
  214. Cls 0
  215. ScreenTags 0,"ScrollText V1.0",#_Width,320,#_Height,256,#_Depth,5,#_BitMap,Addr BitMap(0),#_Exclusive,True
  216.  
  217. db=0    ; start double buffering
  218.  
  219. Repeat
  220.  
  221.   db=1-db         ; change bitmap
  222.   Use BitMap db
  223.   Use Palette 0
  224.  
  225.   ST_Update{}     ; call the update function
  226.  
  227.   ShowBitMap db   ; show the bitmap
  228.   VWait
  229.  
  230. Until Joyb(0)<>0  ; wait mouseclick
  231.  
  232. End
  233.  
  234.